package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.entity.Student;
import com.web.entity.User;
import com.web.service.StudentService;
import com.web.service.UserService;
import com.web.service.impl.StudentServiceImpl;
import com.web.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 更新用户的数据接口
 */
@WebServlet("/updateUser")
public class UpdateUserServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得用户信息参数
        String sId = req.getParameter("id");
        String nickname = req.getParameter("nickname");
        String icon = req.getParameter("icon");
        String email = req.getParameter("email");
        int id = 0;
        if(sId != null){
            id = Integer.parseInt(sId);
        }
        User user = new User();
        user.setIcon(icon);
        user.setId(id);
        user.setNickname(nickname);
        user.setEmail(email);
        //更新用户
        UserService userService = new UserServiceImpl();
        userService.updateUser(user);
        //返回消息
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"OK",null)));
    }
}
